const Mongoose = require('mongoose')

const RecordingSchema = new Mongoose.Schema({
    openid: String,
    recordTime: Number,
    createTime: Date,
    title: String,
    tempFilePath: String,
    upload: Boolean
})

RecordingSchema.statics.get = function (id, callback) {
    this.findOne({_id: id}, callback)
}

RecordingSchema.statics.getList = function (openid, start, callback) {
    this.find({ openid: openid, createTime: { $lt: start } })
        .sort({ createTime: 1 })
        .limit(10)
        .exec(callback)
}

const Recording = Mongoose.model('Recording', RecordingSchema)

module.exports = Recording;